<?php

namespace App\Service\Jpush;
use App\Service\ServiceLog;
use JPush\Client as JPush;

class JpushService
{
    public static function pushMessage($uid,$message = '',$data = array())
    {
        $client = new JPush("5b7f8f7c748bbbf5c1a8eb74", "bbc498e4bda963d2c3fb4047");

        $pusher = $client->push();
        $pusher->setPlatform('all');
        $pusher->addAlias($uid);


        $pusher->iosNotification($message,array(
			'sound' => 'sound.caf',
			'extras' => $data,
		));

        $pusher->androidNotification($message,array(
                'sound' => 'sound.caf',
                'extras' => $data,
            )
        );
        try {
            $res = $pusher->send();
			//var_dump($res);
        } catch (\JPush\Exceptions\JPushException $e) {
            // try something else here
            ServiceLog::record("jpush.txt",$e->getMessage(),"jpush");
        }
        return true;
    }
}